package com.gnkexy.springframework.test;

import cn.hutool.core.io.IoUtil;
import com.gnkexy.springframework.beans.BeansException;
import com.gnkexy.springframework.beans.factory.support.DefaultListableBeanFactory;
import com.gnkexy.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import com.gnkexy.springframework.core.io.DefaultResourceLoader;
import com.gnkexy.springframework.core.io.Resource;
import com.gnkexy.springframework.core.io.ResourceLoader;
import com.gnkexy.springframework.test.bean.UserService;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class ApiTest3 {

    @Test
    public void test() throws BeansException {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
        reader.loadBeanDifinitions("classpath:spring.xml");

        UserService userService = (UserService) beanFactory.getBean("userService");
        String result = userService.queryUserInfo();
        System.out.println("测试结果"+result);
    }




    private ResourceLoader resourceLoader;

    @Before
    public void init() {
        resourceLoader = new DefaultResourceLoader();
    }

    @Test
    public void test_classpath() throws IOException {
        Resource resource = resourceLoader.getResource("classpath:important.properties");
        InputStream inputStream = resource.getInputSteam();
        String content = IoUtil.readUtf8(inputStream);
        System.out.println(content);
    }

}
